import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class Demofs12 {
    void levelOrder(BinaryTree.TreeNode root) {
        List<List<Integer>> lists = new LinkedList<>();
        if(root==null){
            return ;
        }
        Queue<BinaryTree.TreeNode> queue = new LinkedList<BinaryTree.TreeNode>();
        queue.offer(root);
        while(!queue.isEmpty()){
            List<Integer> list = new ArrayList<Integer>();
            int size =queue.size();
            for(int i =0;i<size; i++){
                BinaryTree.TreeNode node = queue.poll();
                list.add(node.val);
                BinaryTree.TreeNode left = node.left;
                BinaryTree.TreeNode right = node.right;
                if (left != null) {
                    queue.offer(left);
                }
                if (right != null) {
                    queue.offer(right);
                }
            }
            lists.add(0,list);

        }
        System.out.println(lists);
    }//
}
